package com.patten.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * Created with IntelliJ IDEA.
 * User: Lv.Dongjie
 * Date: 2018/8/6
 * Time: 16:18
 * Description:
 */
public class GeneralDisplay implements Observer,DisplayElement {

    private float temperature;
    private float humidity;
    Observable observable;

    public GeneralDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("Current condition:"+temperature+"F degrees and "+humidity+"% humidity");
    }

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData2){
            WeatherData2 weatherData2 = (WeatherData2)o;
            this.temperature = temperature;
            this.humidity = humidity;
            display();
        }
    }
}
